package org.gdpu.service.impl;

import org.gdpu.base.DaoSupport;
import org.gdpu.model.TestCategory;
import org.gdpu.service.TestCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-6-5
 * Time: 下午9:05
 * To change this template use File | Settings | File Templates.
 */
@Service
@Transactional
public class TestCategoryServiceImpl extends DaoSupport<TestCategory> implements TestCategoryService {

    @Override
    public List<TestCategory> allTestCategory() {
        Query query = em.createQuery("from TestCategory t");
        return query.getResultList();
    }

    @Override
    public TestCategory findTestCategory(String type){
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("type", type);
        return (TestCategory) this.findSpecialObject(TestCategory.class, params);
    }

    @Override
    public String findTestCategoryById(String id) {
        try {
            TestCategory category = this.find(TestCategory.class, Integer.valueOf(id));
            return category.getType();
        } catch (NumberFormatException e) {
            return "单选题";
        }
    }
}
